package by.android.khan.adapter;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import by.android.khan.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PlaylistAdapter extends ArrayAdapter<JSONObject> {
	
	public PlaylistAdapter(Context ctx, List<JSONObject> list){
		super(ctx, R.layout.adapter_playlist, list);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		JSONObject item = getItem(position);
		if (convertView == null) {
			convertView = View.inflate(getContext(), R.layout.adapter_playlist, null);
			}
		TextView textView1 = (TextView) convertView.findViewById(android.R.id.text1);
		TextView textView2 = (TextView) convertView.findViewById(android.R.id.text2);
		
		try {
			textView1.setText(item.getString("title") +"\n" +item.getString("kind"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		textView2.setText(String.valueOf(position));
		return convertView;
	}

}
